package com.seed.checker;

import lombok.Data;
import lombok.Setter;

/**
 * 检查核心类
 * @author qingqing.liang
 * @create 2017-12-01
 **/
public abstract class Checker<T,S> {

    @Setter
    private Checker next;


    /**
     *
     * @param source 数据来源
     * @param checkItem 检查项
     * @return
     */
    Checker(T source,S checkItem){
    }

    /**
     * 具体的检查类去实现
     * @return
     */
    public abstract boolean doCheck();


    public Result start(){

        Result endResult = new Result();

        check(endResult);

        return endResult;
    }

    /**
     * 链式执行check
     * @param endResult
     */
    private void check(Result endResult ){

        if(this.doCheck()){
            endResult.setPass(true);
            endResult.setMsg("成功");
            if(this.next!= null){
                this.next.check(endResult);
            }
        }else{
            endResult.setPass(false);
            endResult.setMsg("失败");
        }

    }




}
